define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'teacher_audit/index' + location.search,
                    edit_url: 'teacher_audit/edit',
                    multi_url: 'teacher_audit/multi',
                    import_url: 'teacher_audit/import',
                    table: 'teacher_audit',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                showExport: false,
                showToggle: false,
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                // search : false,
                // commonSearch : false,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'status', title: __('Status'),searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')},formatter: Table.api.formatter.status},
                        {field: 'user.nickname',operate: 'LIKE', title: __('User_id'), width: '200',formatter:function(v,row){
                                var html = '<div style="display:flex"><img width="60px" height="60px" src="'+Fast.api.cdnurl(row.user.avatar)+'" /><p style="text-align:left;line-height:20px;margin-top:5px;margin-left:10px">ID:'+row.user.id+'<br/>'+row.user.nickname+'<br/>'+row.user.mobile+'</p></div>';
                                return html;
                            }
                        },
                        {field: 'teaching_method', searchable: false, title: __('Teaching_method'), operate: 'LIKE'},
                        {field: 'settled_type_free', searchable: false, title: __('Settled_type_free'), operate: 'LIKE'},
                        {field: 'settled_type', searchable: false, title: __('Settled_type'), operate: 'LIKE'},
                        {field: 'nickname', searchable: false, title: __('Nickname'), operate: 'LIKE'},
                        {field: 'mobile', searchable: false, title: __('Mobile'), operate: 'LIKE'},
                        {field: 'wx_phone', searchable: false, title: __('Wx_phone'), operate: 'LIKE'},
                        {field: 'realname', searchable: false, title: __('Realname'), operate: 'LIKE'},
                        {field: 'id_code', searchable: false, title: __('Id_code'), operate: 'LIKE'},
                        {field: 'sex', searchable: false, title: __('Sex'), operate: 'LIKE'},
                        {field: 'id_card_front', searchable: false, visible:false,title: __('Id_card_front'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'id_card_reverse', searchable: false, visible:false,title: __('Id_card_reverse'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'school_image', searchable: false, visible:false,title: __('School_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'school_image_hand', searchable: false, visible:false,title: __('School_image_hand'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'school_name', searchable: false, visible:false,title: __('School_name'), operate: 'LIKE'},
                        {field: 'learn_start', searchable: false, visible:false,title: __('Learn_start'), operate: 'LIKE'},
                        {field: 'learn_end', searchable: false, visible:false,title: __('Learn_end'), operate: 'LIKE'},
                        {field: 'education', searchable: false, visible:false,title: __('Education'), operate: 'LIKE'},
                        {field: 'profession', searchable: false, visible:false,title: __('Profession'), operate: 'LIKE'},
                        {field: 'grade', searchable: false, visible:false,title: __('Grade'), operate: 'LIKE'},
                        {field: 'give_lessons_text', searchable: false, visible:false,title: __('Give_lessons'), formatter:function(value,row,index){
                            if(value){
                                let give_lessons_text = '';
                                for (let i=0;i<value.length;i++){
                                    if(i==0){
                                        give_lessons_text += '主教：';
                                    }else{
                                        give_lessons_text += '辅教：';
                                    }
                                    give_lessons_text += value[i].grade_cn + value[i].subject_cn + '-' + value[i].price + '元';
                                    give_lessons_text += '<br/>';
                                }
                                return give_lessons_text;
                            }else{
                                return '';
                            }
                        }},
                        {field: 'give_timesec', searchable: false, visible:false,title: __('Give_timesec'), operate: 'LIKE'},
                        {field: 'give_time_text', searchable: false, visible:false,title: __('Give_time'), formatter:function(value,row,index){
                            if(value){
                                let week_list = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
                                let give_time = '';
                                for (let i=0;i<value.length;i++){
                                    // console.log(value[i]);
                                    if(value[i].morning!==''){
                                        give_time += week_list[i] + value[i].morning + ',';
                                    }
                                    if(value[i].afternoon!==''){
                                        give_time += week_list[i] + value[i].afternoon + ',';
                                    }
                                    if(value[i].night!==''){
                                        give_time += week_list[i] + value[i].night + ',';
                                    }
                                }
                                return give_time;
                            }else{
                                return '';
                            }
                        }},
                        {field: 'holiday_area_text', searchable: false, visible:false,title: __('Holiday_area'), formatter:function(value,row,index){
                            return value[0]+value[1];
                        }},
                        {field: 'unholiday_area_text', searchable: false, visible:false,title: __('Unholiday_area'), formatter:function(value,row,index){
                            return value[0]+value[1];
                        }},
                        {field: 'photo_images', searchable: false, visible:false,title: __('Photo_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'avatar', searchable: false, visible:false,title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'teacher_age', searchable: false, visible:false,title: __('Teacher_age'), formatter:function(value,row,index){
                            return value+='年';
                        }},
                        {field: 'tags_text', searchable: false, visible:false,title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'main_image', searchable: false, visible:false,title: __('Main_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'cert_name', searchable: false, visible:false,title: __('Cert_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cert_image', searchable: false, visible:false, title: __('Cert_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'teacher_exp_text', searchable: false, visible:false, title: __('Teacher_exp'), align: 'left' , formatter:function(value,row,index){
                            if(value){
                                let str = '';
                                for (let i=0;i<value.length;i++){
                                    if(value[i].start!=='' && value[i].end!=='' && value[i].content!==''){
                                        str += i+1 +'：'+ value[i].start + '~' + value[i].end;
                                        str += '<br/>';
                                        str += value[i].content;
                                        if(i!==value.length-1){
                                            str += '<br/>';
                                        }
                                    }
                                }
                                return '<div style="font-size: 12px;width: 400px;white-space: wrap;">'+str+'</div>';
                            }else{
                                return '';
                            }
                        }},
                        {field: 'case_name', searchable: false, visible:false, title: __('Case_name'), formatter:function(value,row,index){
                            let str = '';
                            str += value;
                            str += '<br/>';
                            str += row.case_content;
                            return '<div style="font-size: 12px;width: 400px;white-space: wrap;">'+str+'</div>';
                        }},
                        {field: 'honor_images', searchable: false, visible:false, title: __('Honor_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'person_video', searchable: false, visible:false, title: __('Person_video'), operate: false, events: Table.api.events.file, formatter: Table.api.formatter.file},
                        {field: 'is_fill', title: __('Is_fill'),searchList: {'0':'否','1':'是'},formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
